<template>
  <view class="container">
    <uni-forms ref="form" :modelValue="form" labelWidth="120px" labelPosition="top">
      <view class="background-white bor-top">
        <uni-forms-item name="technology" label="工艺交出措施">
          <uni-file-picker
            class="btn"
            :autoUpload="true"
            v-model="form.tech"
            fileMediatype="all"
            @select="select"
            @progress="progress"
            @success="success"
            @fail="fail"
          />
        </uni-forms-item>
        <uni-forms-item name="staffQualifications" label="人员资质上传">
          <uni-file-picker
            class="btn"
            :autoUpload="true"
            v-model="form.staff"
            fileMediatype="all"
            @select="select2"
            @progress="progress"
            @success="success"
            @fail="fail"
          />
        </uni-forms-item>
        <uni-forms-item name="comment" label="备注">
          <uni-easyinput type="textarea" v-model="form.comment" placeholder="" maxlength="50"></uni-easyinput>
        </uni-forms-item>
      </view>
    </uni-forms>
    <view class="submit-group">
      <button class="u-button" :ripple="true" @click="submit">提交</button>
    </view>
  </view>
</template>

<script>
import { deliver, uploadFileRequest } from '@/api/repair/repair.js'
import config from '@/config.js'
import { getToken } from '@/utils/auth'
export default {
  components: {},
  data() {
    return {
      id: '',
      procTaskId: '',
      form: {
        tech: [],
        technology: '',
        staff: [],
        staffQualifications: '',
        comment: ''
      },
      rules: {
        technology: {
          rules: [
            {
              required: true,
              errorMessage: '工艺交出措施不能为空'
            }
          ]
        },
        staffQualifications: {
          rules: [
            {
              required: true,
              errorMessage: '人员资质上传不能为空'
            }
          ]
        }
      }
    }
  },
  onReady() {
    // this.$refs.form.setRules(this.rules);
  },
  onLoad(option) {
    if (!option.data) return
    let data = JSON.parse(option.data)
    console.log('data', data)
    this.id = data.id
    this.procTaskId = data.procTaskId
  },
  methods: {
    select(val) {
      this.httpRequest('technology', val)
    },
    select2(val) {
      this.httpRequest('staffQualifications', val)
    },
    httpRequest(type, options) {
      const _this = this
      uni.uploadFile({
        url: config.baseUrl + '/file/upload-public',
        header: {
          Authorization: getToken()
        },
        filePath: options.tempFiles[0].path,
        name: 'file',
        success: (res) => {
          let result = JSON.parse(res.data)
          _this.form[type] = result.data.relativeUrl
        },
        complete() {
          // _that.$emit('change', _that.imageList)
        }
      })
    },
    submit() {
      this.$refs.form.validate().then((res) => {
        let data = {
          id: this.id,
          procTaskId: this.procTaskId,
          deviceExamineWorkflowEntity: {
            examineId: this.id,
            opinionType: 'PASS'
          },
          deliverInfo: this.form
        }
        deliver(data).then((res) => {
          this.$modal.showToast('处理成功')
          uni.$emit('refresh')
          uni.navigateBack()
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  margin-bottom: 200rpx;

  .background-white {
    background-color: #fff;
    padding: 20rpx 30rpx;
    box-sizing: border-box;

    .uni-forms-item__label {
      color: #333;
      font-size: 30rpx;
    }

    .bor-btm {
      display: flex;
      border-bottom: 1px solid #d5d7e3;
    }

    .photo {
      display: flex;
      justify-content: space-between;

      image {
        width: 214rpx;
        height: 214rpx;
      }
    }

    .text {
      padding-bottom: 20rpx;
      padding-top: 4rpx;
      color: #333;

      text {
        color: #666;
      }
    }
  }
}

.hidden-title {
  background: #f5f5f5;
  padding: 20rpx;
  color: #999;
}

.bor-top {
  border-top: 20rpx solid #f5f5f5;
}

.blue {
  color: #88b4c4;
}

.icon-style {
  width: 52rpx;
  height: 42rpx;
  padding-right: 10rpx;
}
.input {
  display: inline-block;
  width: 100%;
  background-color: #f5f5f5;
  padding: 20rpx;
  font-size: 28rpx;
  border-radius: 10rpx;
  height: 60rpx;
}
</style>
